package org.jivesoftware.smack;

import java.io.Reader;
import java.io.Writer;
import java.lang.reflect.Constructor;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentLinkedQueue;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.concurrent.CopyOnWriteArraySet;
import java.util.concurrent.atomic.AtomicInteger;
import org.jivesoftware.smack.compression.Java7ZlibInputOutputStream;
import org.jivesoftware.smack.compression.JzlibInputOutputStream;
import org.jivesoftware.smack.compression.XMPPInputOutputStream;
import org.jivesoftware.smack.debugger.SmackDebugger;
import org.jivesoftware.smack.filter.PacketFilter;
import org.jivesoftware.smack.packet.Packet;
import org.jivesoftware.smack.packet.Presence;
import org.jivesoftware.smack.packet.Presence.Type;

public abstract class Connection
{
  private static final AtomicInteger connectionCounter = new AtomicInteger(0);
  private static final Set<ConnectionCreationListener> connectionEstablishedListeners = new CopyOnWriteArraySet();
  protected static final List<XMPPInputOutputStream> compressionHandlers = new ArrayList(2);
  public static boolean DEBUG_ENABLED = false;
  protected final Collection<ConnectionListener> connectionListeners = new CopyOnWriteArrayList();
  protected final Collection<PacketCollector> collectors = new ConcurrentLinkedQueue();
  protected final Map<PacketListener, ListenerWrapper> recvListeners = new ConcurrentHashMap();
  protected final Map<PacketListener, ListenerWrapper> sendListeners = new ConcurrentHashMap();
  protected final Map<PacketInterceptor, InterceptorWrapper> interceptors = new ConcurrentHashMap();
  private AccountManager accountManager = null;
  protected ChatManager chatManager = null;
  protected SmackDebugger debugger = null;
  protected Reader reader;
  protected Writer writer;
  protected RosterStorage rosterStorage;
  protected SASLAuthentication saslAuthentication = new SASLAuthentication(this);
  protected final int connectionCounterValue = connectionCounter.getAndIncrement();
  protected final ConnectionConfiguration config;
  private String serviceCapsNode;
  protected XMPPInputOutputStream compressionHandler;
  protected boolean released = false;

  static
  {
    try
    {
      DEBUG_ENABLED = Boolean.getBoolean("smack.debugEnabled");
    }
    catch (Exception localException)
    {
    }
    SmackConfiguration.getVersion();
    compressionHandlers.add(new Java7ZlibInputOutputStream());
    compressionHandlers.add(new JzlibInputOutputStream());
  }

  public abstract void release();

  public boolean isReleased()
  {
    return this.released;
  }

  protected Connection(ConnectionConfiguration paramConnectionConfiguration)
  {
    this.config = paramConnectionConfiguration;
  }

  public ConnectionConfiguration getConfiguration()
  {
    return this.config;
  }

  public String getServiceName()
  {
    return this.config.getServiceName();
  }

  public String getHost()
  {
    return this.config.getHost();
  }

  public int getPort()
  {
    return this.config.getPort();
  }

  public abstract String getUser();

  public abstract String getConnectionID();

  public abstract boolean isConnected();

  public abstract boolean isAuthenticated();

  public abstract boolean isAnonymous();

  public abstract boolean isSecureConnection();

  protected boolean isReconnectionAllowed()
  {
    return this.config.isReconnectionAllowed();
  }

  public abstract boolean isUsingCompression();

  public abstract void connect()
    throws Exception;

  public void login(String paramString1, String paramString2)
    throws XMPPException
  {
    login(paramString1, paramString2, "Smack");
  }

  public abstract void login(String paramString1, String paramString2, String paramString3)
    throws XMPPException;

  public abstract void loginAnonymously()
    throws XMPPException;

  public abstract void sendPacket(Packet paramPacket);

  public AccountManager getAccountManager()
  {
    if (this.accountManager == null)
      this.accountManager = new AccountManager(this);
    return this.accountManager;
  }

  public synchronized ChatManager getChatManager()
  {
    if (this.chatManager == null)
      this.chatManager = new ChatManager(this);
    return this.chatManager;
  }

  public abstract Roster getRoster();

  public abstract void setRosterStorage(RosterStorage paramRosterStorage)
    throws IllegalStateException;

  public SASLAuthentication getSASLAuthentication()
  {
    return this.saslAuthentication;
  }

  public void disconnect()
  {
    disconnect(new Presence(Presence.Type.unavailable));
  }

  public abstract void disconnect(Presence paramPresence);

  public static void addConnectionCreationListener(ConnectionCreationListener paramConnectionCreationListener)
  {
    connectionEstablishedListeners.add(paramConnectionCreationListener);
  }

  public static void removeConnectionCreationListener(ConnectionCreationListener paramConnectionCreationListener)
  {
    connectionEstablishedListeners.remove(paramConnectionCreationListener);
  }

  protected static Collection<ConnectionCreationListener> getConnectionCreationListeners()
  {
    return Collections.unmodifiableCollection(connectionEstablishedListeners);
  }

  public void addConnectionListener(ConnectionListener paramConnectionListener)
  {
    if (paramConnectionListener == null)
      return;
    if (!this.connectionListeners.contains(paramConnectionListener))
      this.connectionListeners.add(paramConnectionListener);
  }

  public void removeConnectionListener(ConnectionListener paramConnectionListener)
  {
    this.connectionListeners.remove(paramConnectionListener);
  }

  protected Collection<ConnectionListener> getConnectionListeners()
  {
    return this.connectionListeners;
  }

  public PacketCollector createPacketCollector(PacketFilter paramPacketFilter)
  {
    PacketCollector localPacketCollector = new PacketCollector(this, paramPacketFilter);
    this.collectors.add(localPacketCollector);
    return localPacketCollector;
  }

  protected void removePacketCollector(PacketCollector paramPacketCollector)
  {
    this.collectors.remove(paramPacketCollector);
  }

  protected Collection<PacketCollector> getPacketCollectors()
  {
    return this.collectors;
  }

  public void addPacketListener(PacketListener paramPacketListener, PacketFilter paramPacketFilter)
  {
    if (paramPacketListener == null)
      throw new NullPointerException("Packet listener is null.");
    ListenerWrapper localListenerWrapper = new ListenerWrapper(paramPacketListener, paramPacketFilter);
    this.recvListeners.put(paramPacketListener, localListenerWrapper);
  }

  public void removePacketListener(PacketListener paramPacketListener)
  {
    this.recvListeners.remove(paramPacketListener);
  }

  protected Map<PacketListener, ListenerWrapper> getPacketListeners()
  {
    return this.recvListeners;
  }

  public void addPacketSendingListener(PacketListener paramPacketListener, PacketFilter paramPacketFilter)
  {
    if (paramPacketListener == null)
      throw new NullPointerException("Packet listener is null.");
    ListenerWrapper localListenerWrapper = new ListenerWrapper(paramPacketListener, paramPacketFilter);
    this.sendListeners.put(paramPacketListener, localListenerWrapper);
  }

  public void removePacketSendingListener(PacketListener paramPacketListener)
  {
    this.sendListeners.remove(paramPacketListener);
  }

  protected Map<PacketListener, ListenerWrapper> getPacketSendingListeners()
  {
    return this.sendListeners;
  }

  protected void firePacketSendingListeners(Packet paramPacket)
  {
    Iterator localIterator = this.sendListeners.values().iterator();
    while (localIterator.hasNext())
    {
      ListenerWrapper localListenerWrapper = (ListenerWrapper)localIterator.next();
      localListenerWrapper.notifyListener(paramPacket);
    }
  }

  public void addPacketInterceptor(PacketInterceptor paramPacketInterceptor, PacketFilter paramPacketFilter)
  {
    if (paramPacketInterceptor == null)
      throw new NullPointerException("Packet interceptor is null.");
    this.interceptors.put(paramPacketInterceptor, new InterceptorWrapper(paramPacketInterceptor, paramPacketFilter));
  }

  public void removePacketInterceptor(PacketInterceptor paramPacketInterceptor)
  {
    this.interceptors.remove(paramPacketInterceptor);
  }

  public boolean isSendPresence()
  {
    return this.config.isSendPresence();
  }

  protected Map<PacketInterceptor, InterceptorWrapper> getPacketInterceptors()
  {
    return this.interceptors;
  }

  protected void firePacketInterceptors(Packet paramPacket)
  {
    if (paramPacket != null)
    {
      Iterator localIterator = this.interceptors.values().iterator();
      while (localIterator.hasNext())
      {
        InterceptorWrapper localInterceptorWrapper = (InterceptorWrapper)localIterator.next();
        localInterceptorWrapper.notifyListener(paramPacket);
      }
    }
  }

  protected void initDebugger()
  {
    if ((this.reader == null) || (this.writer == null))
      throw new NullPointerException("Reader or writer isn't initialized.");
    if (this.config.isDebuggerEnabled())
      if (this.debugger == null)
      {
        String str = null;
        try
        {
          str = System.getProperty("smack.debuggerClass");
        }
        catch (Throwable localThrowable)
        {
        }
        Class localClass = null;
        if (str != null)
          try
          {
            localClass = Class.forName(str);
          }
          catch (Exception localException1)
          {
            localException1.printStackTrace();
          }
        if (localClass == null)
          try
          {
            localClass = Class.forName("org.jivesoftware.smack.debugger.FileDebugger");
          }
          catch (Exception localException2)
          {
          }
        if (localClass == null)
          try
          {
            localClass = Class.forName("de.measite.smack.AndroidDebugger");
          }
          catch (Exception localException3)
          {
            try
            {
              localClass = Class.forName("org.jivesoftware.smack.debugger.ConsoleDebugger");
            }
            catch (Exception localException5)
            {
              localException5.printStackTrace();
            }
          }
        try
        {
          Constructor localConstructor = localClass.getConstructor(new Class[] { Connection.class, Writer.class, Reader.class });
          this.debugger = ((SmackDebugger)localConstructor.newInstance(new Object[] { this, this.writer, this.reader }));
          this.reader = this.debugger.getReader();
          this.writer = this.debugger.getWriter();
        }
        catch (Exception localException4)
        {
          throw new IllegalArgumentException("Can't initialize the configured debugger!", localException4);
        }
      }
      else
      {
        this.reader = this.debugger.newConnectionReader(this.reader);
        this.writer = this.debugger.newConnectionWriter(this.writer);
      }
  }

  protected void setServiceCapsNode(String paramString)
  {
    this.serviceCapsNode = paramString;
  }

  public String getServiceCapsNode()
  {
    return this.serviceCapsNode;
  }

  protected static class InterceptorWrapper
  {
    private PacketInterceptor packetInterceptor;
    private PacketFilter packetFilter;

    public InterceptorWrapper(PacketInterceptor paramPacketInterceptor, PacketFilter paramPacketFilter)
    {
      this.packetInterceptor = paramPacketInterceptor;
      this.packetFilter = paramPacketFilter;
    }

    public boolean equals(Object paramObject)
    {
      if (paramObject == null)
        return false;
      if ((paramObject instanceof InterceptorWrapper))
        return ((InterceptorWrapper)paramObject).packetInterceptor.equals(this.packetInterceptor);
      if ((paramObject instanceof PacketInterceptor))
        return paramObject.equals(this.packetInterceptor);
      return false;
    }

    public void notifyListener(Packet paramPacket)
    {
      if ((this.packetFilter == null) || (this.packetFilter.accept(paramPacket)))
        this.packetInterceptor.interceptPacket(paramPacket);
    }
  }

  protected static class ListenerWrapper
  {
    private PacketListener packetListener;
    private PacketFilter packetFilter;

    public ListenerWrapper(PacketListener paramPacketListener, PacketFilter paramPacketFilter)
    {
      this.packetListener = paramPacketListener;
      this.packetFilter = paramPacketFilter;
    }

    public void notifyListener(Packet paramPacket)
    {
      if ((this.packetFilter == null) || (this.packetFilter.accept(paramPacket)))
        this.packetListener.processPacket(paramPacket);
    }
  }
}

/* Location:           D:\hygieia\userclient\common\libs\easemobchat_2.1.8.jar
 * Qualified Name:     org.jivesoftware.smack.Connection
 * JD-Core Version:    0.6.1
 */